/******************************************************
*  Copyright(c) pages.ilovezxl.top
*  FileName : uart_linux.c
*  Author : rivulet.dave
*  Description : uart Linux平台实现
*  Data : 2020-08-01
******************************************************/

/*********************************************************************
 * INCLUDES
 */

#include "stdrope.h"

#include "hallib.h"
#include "halagent.h"

#if (HAL_UART == _ENABLE && HAL_PRODUCER == _HAL_LINUX_)

#include <pthread.h>
#include <linux/input.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>

#include "log.h"
#include "uart_linux.h"

/*********************************************************************
 *  EXTERNAL VARIABLES
 */

/*********************************************************************
 * MACROS
 */

#define MOD_NAME                TOSTR(HW_UART)

/*********************************************************************
 * TYPES
 */

typedef struct _uart_linux_cb
{
    HAL_OPER_S stBaseObj;  //须在第一个位置
} UART_LINUX_CB_S;

/*********************************************************************
 * FUNCTIONS DECLARE
 */

static hd_t UART_OpenByLinux(uint32_t uiIdx);
static int32_t UART_CloseByLinux(hd_t hModuleDescriptor);
static int32_t UART_ReadByLinux(hd_t hModuleDescriptor, uint8_t *pUserBuf, uint32_t uiSize, uint32_t uiFlag);
static int32_t UART_WriteByLinux(hd_t hModuleDescriptor, const uint8_t *pUserData, uint32_t uiSize, uint32_t uiFlag);
static int32_t UART_ReadOnceByLinux(uint32_t uiIdx, uint8_t *pUserBuf, uint32_t uiSize, uint32_t uiFlag);
static int32_t UART_WriteOnceByLinux(uint32_t uiIdx, const uint8_t *pUserData, uint32_t uiSize, uint32_t uiFlag);
static int32_t UART_CtrlByLinux(hd_t hModuleDescriptor, uint32_t uiCmdKey, void *pValue);
static int32_t UART_LockByLinux(hd_t hModuleDescriptor, uint32_t uiFlag);
static int32_t UART_UnlockByLinux(hd_t hModuleDescriptor, uint32_t uiFlag);

/*********************************************************************
 * VARIABLES
 */

static HAL_OPER_S s_stUartBaseLinuxObj;
static UART_LINUX_CB_S s_astUartLinuxCb[HAL_UART_NUM];
static char *s_acUartNameList[] = HAL_UART_NAMES;

/*********************************************************************
 * FUNCTIONS
 */

/**
 *   @Description: UART初始化相关接口，指针
 *   @param : NA
 *   @return: 结构体指针
 */
HAL_OPER_S *UART_ObjNewByLinux(void)
{
    s_stUartBaseLinuxObj.pThis = &s_stUartBaseLinuxObj;
    s_stUartBaseLinuxObj.pfOpen = UART_OpenByLinux;
    s_stUartBaseLinuxObj.pfClose = UART_CloseByLinux;
    s_stUartBaseLinuxObj.pfLock = UART_LockByLinux;
    s_stUartBaseLinuxObj.pfUnlock = UART_UnlockByLinux;
    s_stUartBaseLinuxObj.pfRead = UART_ReadByLinux;
    s_stUartBaseLinuxObj.pfWrite = UART_WriteByLinux;
    s_stUartBaseLinuxObj.pfReadOnce = UART_ReadOnceByLinux;
    s_stUartBaseLinuxObj.pfWriteOnce = UART_WriteOnceByLinux;
    s_stUartBaseLinuxObj.pfCtrl = UART_CtrlByLinux;
    
    for (uint32_t i = 0; i < HAL_UART_NUM; i++)
    {
        s_astUartLinuxCb[i].pName = s_acUartNameList[i];
    }
    return &s_stUartBaseLinuxObj;
}

/**
 *   @Description: UART去初始化、退出
 *   @param : NA
 *   @return: _OK/_ERR
 */
int32_t UART_ObjDeleteByLinux(void)
{
    return _OK;
}

static hd_t UART_OpenByLinux(uint32_t uiIdx)
{
    return NULL;
}

static int32_t UART_CloseByLinux(hd_t hModuleDescriptor)
{
    return _OK;
}

static int32_t UART_ReadByLinux(hd_t hModuleDescriptor, uint8_t *pUserBuf, uint32_t uiSize, uint32_t uiFlag)
{
    return _OK;
}

static int32_t UART_WriteByLinux(hd_t hModuleDescriptor, const uint8_t *pUserData, uint32_t uiSize, uint32_t uiFlag)
{
    return _OK;
}

static int32_t UART_ReadOnceByLinux(uint32_t uiIdx, uint8_t *pUserBuf, uint32_t uiSize, uint32_t uiFlag)
{
    return _OK;
}

static int32_t UART_WriteOnceByLinux(uint32_t uiIdx, const uint8_t *pUserData, uint32_t uiSize, uint32_t uiFlag)
{
    return _OK;
}

static int32_t UART_CtrlByLinux(hd_t hModuleDescriptor, uint32_t uiCmdKey, void *pValue)
{
    return _OK;
}

static int32_t UART_LockByLinux(hd_t hModuleDescriptor, uint32_t uiFlag)
{
    return _OK;
}

static int32_t UART_UnlockByLinux(hd_t hModuleDescriptor, uint32_t uiFlag)
{
    return _OK;
}


#endif  // HAL_UART == _ENABLE && HAL_PRODUCER == _HAL_LINUX_

/************************************** The End Of File **************************************/

